class LoginView extends BaseEuiView {
    public constructor($controller:BaseController, $parent:eui.Group){
        super($controller, $parent);
        this.skinName = "resource/skins/LoginSkin.exml";
    }
    private saizi:eui.Image;
    private textInput_roleName:eui.TextInput;
    private label_roleName:eui.Label;
    private go:eui.Image;
    private go_icon:eui.Image;

    //主角
    private yaoluan_nan:eui.Image;
    private yaoluan_nu:eui.Image;
    private yijian_nan:eui.Image;
    private yijian_nu:eui.Image;
    private yuezhang_nan:eui.Image;
    private yuezhang_nu:eui.Image;
    private lieqiang_nan:eui.Image;
    private lieqiang_nu:eui.Image;

    //选中角色
    private roleAttack:eui.Image;
    private selectRole:eui.Image;

    private curSelectRole:eui.Image;//当前选择的
    private isMoveFinished:boolean = true;

    /**
     *对面板进行显示初始化，用于子类继承
     *
     */
    public initUI():void{
        super.initUI();
        this.yaoluan_nan.visible = false;
        this.textInput_roleName.addEventListener(egret.TouchEvent.TOUCH_BEGIN,(e) => {
            this.label_roleName.text='';
        }, this);
        this.saizi.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onSaizi, this);
        this.go.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onLogin, this);
        this.go_icon.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onLogin, this);
        //人物选择事件
        this.yaoluan_nan.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onSelectRole,this);
        this.yaoluan_nu.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onSelectRole,this);
        this.yijian_nan.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onSelectRole,this);
        this.yijian_nu.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onSelectRole,this);
        this.yuezhang_nan.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onSelectRole,this);
        this.yuezhang_nu.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onSelectRole,this);
        this.lieqiang_nan.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onSelectRole,this);
        this.lieqiang_nu.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onSelectRole,this);
    }

    /**
     * 摇塞子
     */
    private onSaizi(event:egret.TouchEvent):void{
        this.label_roleName.text = "嫦娥";
    }

    /**
     * 请求登陆处理
     */
    private onLogin(event:egret.TouchEvent):void{
        var userName:string = "嫦娥";
        //进行基础检测
        this.applyFunc(LoginConst.LOGIN_C2S, userName, "pwd");
    }

    /**
     * 选择角色
     */
    private onSelectRole(event:egret.TouchEvent):void{
        if(!this.isMoveFinished){
            return;
        }
        this.yaoluan_nan.visible = true;
        this.isMoveFinished = false;
        if(this.curSelectRole){
            this.curSelectRole.visible = true;
        }
        event.currentTarget.visible = false;
        this.curSelectRole = event.$currentTarget;

        this.selectRole.texture = this.curSelectRole.texture;
        this.selectRole.source = this.curSelectRole.source;
        this.selectRole.x = this.curSelectRole.x;
        this.selectRole.y = this.curSelectRole.y;
        egret.Tween.get(this.selectRole).to({x:491,y:203},250,egret.Ease.sineIn).call(function(){
            this.isMoveFinished = true;
        },this);

        let str = this.selectRole.source.toString().split("_")[0];
        this.roleAttack.texture = RES.getRes(str+"_icon_png");
        this.roleAttack.scaleX=0.5;
        this.roleAttack.scaleY=0.5;
        this.roleAttack.alpha=0.5;
        egret.Tween.get(this.roleAttack).to({scaleX:1,scaleY:1,alpha:1},600,egret.Ease.sineIn).call(function(){
            this.isMoveFinished = true
        },this); 
    }

    /**
     * 登陆成功处理
     */
    public loginSuccess(tips:string):void{
        this.label_roleName.text = tips;
    }
}